import axios from 'axios'
import { useCounterStore } from '@/stores/counter.js'

const instance = new axios.create({
  baseURL: 'http://localhost:8080/api',
  timeout: 2000,
  headers: {
    'Content-Type': 'multipart/form-data',
  },
})

instance.interceptors.request.use(
  (config) => {
    // Do something before request is sent
    const counterStore = useCounterStore()
    console.log(counterStore.count)
    config.headers['token'] = counterStore.count
    console.log(config.headers['token'])
    return config
  },
  (error) => {
    // Do something with request error
    return Promise.reject(error)
  },
)
instance.interceptors.response.use(
  (response) => {
    // Do something before response is sent
    return response
  },
  (error) => {
    // Do something with response error
    return Promise.reject(error)
  },
)
export default instance
